<?php
include('validate_configure.php');
include('validate_util.php');
include('validate_func.php');

class CommonValidator {
	
	function validate($validate_item_id, $COMMON_VALIDATE_CONFIG, $context=null) {
		
		$configure = new ValidateConfigure($COMMON_VALIDATE_CONFIG, $context);
		
		$validate_config = $configure->get_validate_config();
				
		$validate_func_obj = new ValidateFunc($configure);
		
		$validate_item = $validate_config[$validate_item_id];
		
		if($validate_item == null) {
			$this->log("error, validate_item is null");
			return;
		}
	
		$error_list = array();
			
		for($i = 0; $i < count($validate_item); $i++) {
			$item = $validate_item[$i];
			$id = $item['id'];
			$descName = $item['descName'];
			$validate_func = $item['validate_func'];
			$advice_id = $item['advice_id'];
			if($advice_id == null) {
				$advice_id = "advice_" . $id;
			}
			
			for($j = 0; $j < count($validate_func); $j++) {
				
				$func = $validate_func[$j];
				
				$error_list = $validate_func_obj->$func['func_name']($id, $advice_id, $descName, $func['func_param'], $error_list);
			}
		}
		
		return $error_list;
	}		

	function log($msg) {
		echo $msg;
	}  
}

?>
